package org.thread.test05.demo01;

import java.util.concurrent.TimeUnit;

/**
 * 定义一个线程类 - 实现数据采集 -
 * @author ZJL
 * @date 2025-03-11
 */
public class DataCollectionThread extends Thread {
    @Override
    public void run() {
        while (true) {
            System.out.println("采集数据中...");
            try {
                // 每隔两秒采集一次
                TimeUnit.SECONDS.sleep(2);
//                Thread.sleep(2000);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
            boolean flag = Thread.currentThread().isInterrupted();
            if (flag) {
                System.out.println("采集结束！");
                break;
            }
        }
    }
}
